<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<style type="text/css">
	body {
		background: #404066;
		color: #000000;
		font: 10pt verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;
		margin: 5px 10px 10px 10px;
		padding: 0px;
		overflow: hidden;
	}
	h1 {
		color: darkblue;
		font :bold 16pt verdana,geneva,lucida,'lucida grande',arial,helvetica,sans-serif;
		margin-top: 0
	}
	.title {
		text-align: center;
	}
	h2 {
		color:darkblue;
		font:bold 14pt verdana,geneva,lucida,'lucida grande',arial,helvetica,sans-serif
	}
	h3 {
		color:darkblue;
		font:bold 12pt verdana,geneva,lucida,'lucida grande',arial,helvetica,sans-serif
	}
	h4 {
		color:#b73235;
		font:bold 10pt verdana,geneva,lucida,'lucida grande',arial,helvetica,sans-serif
	}
	pre {
		font: 10pt parallax,courier,monospaced;
		line-height: 97%;
	}	
	.source {
		margin-left: 20px;
		border: 1px solid #ccc;
		overflow: auto;
		display: none;
		background: #f8f8e8;
		margin-top: 12pt;
		width: 95%;
		padding-top: 5px;
		padding-left: 10px;
		max-height: 600px;
		letter-spacing: 0px;
	}
	var {
		color: #000080;
		font-style: normal;
		font-weight: bold;
		letter-spacing: -1px;
	}
	a {
		font-weight: bold;
		font-size: 6pt;
		text-decoration: none;
		color: #0000cc;
	}
	.toc1 {
		font-size: 12pt;
		font-weight: bold;
		vertical-align: baseline;
		text-align: center;
		color: #d7d0ff;
	}		
	.toc2 {
		font-size: 95%;
		font-weight: bold;
		vertical-align: baseline;
		color: white;
		text-decoration: none;
	}		
	.toc3 {
		font-size: 90%;
		font-weight: normal;
		vertical-align: baseline;
		margin-left: 10px;
		color: white;
		text-decoration: none;
	}		
	.toc4 {
		font-size: 85%;
		font-weight: normal;
		font-style: italic;
		vertical-align: baseline;
		margin-left: 20px;
		color: #d7d0ff;
		text-decoration: none;
	}
	.tocgrp {
		display: none
	}
  hr {
  	border: 0;
    color: #b73235;
    background-color: #b73235;
    height: 1px;
  }
	</style>
	<script language="JavaScript">
		window.onload = resize;
		window.onresize = resize;
		var show=0;
		function ShowHide(divId) {
			if (document.getElementById(divId).style.display!='block') {
				document.getElementById(divId).style.display='block';
				if (divId.substring(0, 3) == 'toc') {
					window.location = '#lbl' + divId.substring(3);
				}
			} else {
				document.getElementById(divId).style.display='none';
			}
		};
    function resize() {
      var myWidth = 0, myHeight = 0;
      if(typeof(window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
      } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
      } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
      document.getElementById("text").style.height = (myHeight - 10) + "px";
      document.getElementById("text").style.width = (Math.min(myWidth - 250, 800)) + "px";
      document.getElementById("toc").style.height = (myHeight - 10) + "px";
     }	
    function selectall(source) { 
	    var selection, range, doc, win; 
	    if ( (doc = source.ownerDocument)
	    	&& (win = doc.defaultView)
	    	&& typeof win.getSelection != 'undefined'
	    	&& typeof doc.createRange != 'undefined' 
	    	&& (selection = window.getSelection())
	    	&& typeof selection.removeAllRanges != 'undefined'
	    ) { 
	       range = doc.createRange(); 
	       range.selectNode(source); 
	       selection.removeAllRanges(); 
	       selection.addRange(range); 
	    } else if (document.body && typeof document.body.createTextRange != 'undefined' && (range = document.body.createTextRange())) { 
	       range.moveToElementText(source); 
	       range.select(); 
	    } 
		}
  </script>
</head>
<body style = "margin: 0 0 0 0;">
<div align=center>
<table cellpadding=0 cols=2 border=0>
	<tr><td valign="top">
	<div id="toc" style= "width: 200px; height: 600px; overflow: auto; background-color: #222255; border-left: solid #ffffe0"><br/>
		<div style="background-color:#222255; width: 100%; text-align: center">
		<img src="data:image/gif;base64,
			R0lGODlhrwBFALMAABAIPyIiVRwQYDUrcjQmSkwnSk9OW2wrQp1PYKgxMU1KiKCeqvv7++Tk58rJ
			0G5niiwAAAAArwBFAAAI/gADCBxIsKDBgwgTKlzIsKHDhxAjSpxIsaLFixgzatzIsaPHjyAfEhhJ
			cmSBkyhTqlzJsqXLlzBjypxJs2bJkRhL1tzJs6fPn0BhlqyoM6jRo0iTAiUpsajKA1CjSp1KtarV
			q1izat3KtatXqCuZOnSK0mqCs2jTql3Ltq3bt3Djyp1L123VlDgbknwqta7fv4ADCx5sF2XehXtT
			Rl2LoLHjx5AjS55MubLly5gza97c+OwBwwQQmywLNW3jB6hTq17NurXr17Bjy55Nu7Zt1QgSfD55
			GOHok4vPIkitoLjx48iTK1/OvLnz59CjS59u/EHu3bwV/i4QfPgD4wPC/osfT768+fPo06tfz769
			+/fhFVjXjT2079+lhX9XMF6A//8ABijggAQWaOCBCCao4IIMxnddfQnhl99w/IXH4IUYZqjhhhwK
			6CB9ht1H2gH6VdjhiSimqGKDAyiQm24hHiRhiRauaOONOHb4IYgF2FfQjAlQaCEARBZppJEKHqkk
			kggCAKCTOf4HJZQMUhngklYKsCNYPcpIAGlnfWchAQaUaeaZaGZ5JZlotmmmmk+SGYB/ABhAQJQA
			yDkSnAUGYKeAfrppwJz+bbmbjwMBKeYAAhCwAAOQRiqppA08wGedDkyqaaSVXupoAwYQaYADC/DZ
			YZ4LgLqAA6Em+UAD/6U+aUADm7IKpaHZ/fglcCQKOUCemTYg7LDEDstApwJiCmmxzAp7rKXJEpAp
			A5YC8MCxpm6IKqQPPApqtnS+ykCsUo7qwLnoktqqli2+yCWiAo02oYnAUivomcFCW+60495rprf6
			0iltpNVe2wC4GNbL7cDfGmgtrQvceWWeNxFA5H+4dvkjmAmIKXCmoWJZ5KgMOGDxx8dyK3KRjpZ8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pjng1DhqO
			Y5fKoqaO8pfP/OY7f/mpeVHSNm587BZAOJzJvva3z/3ugntf+sQvPkPwQ5jym//86A+MVPCS9Pt8
			Mzjpj7/8518Xqqgk7qJh2oi+wv/++///APh/YYF/45cYKxGACJiACriAd+ESBDgWBqgUEjiBFHgU
			N0EUZFGBGriBHFh8DzgRcRWCIjiCJFiCJniCKJiCKoiCIdGCLviCMBiDMjiDNAiDAQEAOw==
		">
		</div>
		<div style="font: bold 11pt verdana,geneva,lucida,'lucida grande',arial,helvetica,sans-serif;color:white; text-align: center; margin-bottom: 10px; margin-top: 10px">DHCP</div>
		<p class = "toc1">Table of Contents</p>
		<div style = "text-align: left; margin-left: 10px;">
			<a href= "#lbl1" class = "toc2">Preface</a><br/>
<a href= "#lbl2" class = "toc2">Global CONstants </a><br/>
<a href= "#lbl4" class = "toc2">Global DATa </a><br/>
<a href= "#lbl6" class = "toc2">Used OBJects </a><br/>
<a href= "#lbl8" class = "toc2">PUBlic Spin Methods</a><br/>
<a href= "#lbl9" class = "toc4">Init</a><br/>
<a href= "#lbl11" class = "toc4">SetHostname</a><br/>
<a href= "#lbl13" class = "toc4">GetErrorCode</a><br/>
<a href= "#lbl15" class = "toc4">GetErrorMessage</a><br/>
<a href= "#lbl17" class = "toc4">GetLeaseTime</a><br/>
<a href= "#lbl19" class = "toc4">GetIp</a><br/>
<a href= "#lbl21" class = "toc4">SetRequestIp</a><br/>
<a href= "#lbl23" class = "toc4">IsRequestIp</a><br/>
<a href= "#lbl25" class = "toc4">GetRequestIP</a><br/>
<a href= "#lbl27" class = "toc4">SetRouter</a><br/>
<a href= "#lbl29" class = "toc4">GetRouter</a><br/>
<a href= "#lbl31" class = "toc4">SetDhcpServer</a><br/>
<a href= "#lbl33" class = "toc4">GetDhcpServer</a><br/>
<a href= "#lbl35" class = "toc4">SetNtpServer</a><br/>
<a href= "#lbl37" class = "toc4">GetNtpServer</a><br/>
<a href= "#lbl39" class = "toc4">DoDhcp</a><br/>
<a href= "#lbl41" class = "toc4">RenewDhcp</a><br/>
<a href= "#lbl43" class = "toc4">SendReceive</a><br/>
<a href= "#lbl45" class = "toc4">SendReceive</a><br/>
<a href= "#lbl47" class = "toc4">UpdRxLen</a><br/>
<a onclick ="javascript:ShowHide('toc49')" href="javascript:;" class = "toc2">PRIvate Spin Methods ... </a><br />
<div id= "toc49" class = "tocgrp">
<a href= "#lbl50" class = "toc4">DiscoverOffer</a><br/>
<a href= "#lbl52" class = "toc4">RequestAck</a><br/>
<a href= "#lbl54" class = "toc4">InitRequest</a><br/>
<a href= "#lbl56" class = "toc4">Discover</a><br/>
<a href= "#lbl58" class = "toc4">Offer</a><br/>
<a href= "#lbl60" class = "toc4">Request</a><br/>
<a href= "#lbl62" class = "toc4">Ack</a><br/>
<a href= "#lbl64" class = "toc4">GetSetIp</a><br/>
<a href= "#lbl66" class = "toc4">FillOpHTypeHlenHops</a><br/>
<a href= "#lbl68" class = "toc4">CreateTransactionId</a><br/>
<a href= "#lbl70" class = "toc4">FillLeaseTime</a><br/>
<a href= "#lbl72" class = "toc4">FillTransactionID</a><br/>
<a href= "#lbl74" class = "toc4">FillMac</a><br/>
<a href= "#lbl76" class = "toc4">FillServerIp</a><br/>
<a href= "#lbl78" class = "toc4">FillMagicCookie</a><br/>
<a href= "#lbl80" class = "toc4">WriteDhcpOption</a><br/>
<a href= "#lbl82" class = "toc4">ReadDhcpOption</a><br/>
<a href= "#lbl84" class = "toc4">EndDhcpOptions</a><br/>
</div>
<a href= "#lbl86" class = "toc2">Documentation </a><br/>
<a href= "#lbl87" class = "toc2">MIT License </a><br/>

		</div>
	</div>
	</td>
	<td>
		<div id="text" style= "text-align: left; padding-left: 20px; padding-right: 20px; width: 800px; height: 600px; background-color: #ffffe0; overflow: auto">
			<h1 id = "lbl1" class = "title">DHCP </h1>

<br /><br />
AUTHOR:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mike Gebhard<br />
COPYRIGHT:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parallax Inc.<br />
LAST MODIFIED:&nbsp;&nbsp;&nbsp;&nbsp;10/19/2013<br />
VERSION:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.0<br />
LICENSE:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MIT (see end of file)<br /><br />
DESCRIPTION:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The DHCP object<br />
<br />
MODIFICATIONS:<br />
 8/31/2013&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;added option to set hostname. default is propnet as before<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;but after Init you can do SetHostname(string("MYPROP")) to chose another<br />
10/04/2013&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;added minimal spindoc comments<br />
10/19/2013&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;moved SendReceive to socket<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Michael Sommer (MSrobots)<br />

<br />
<h2 id = "lbl2">Global CONstants </h2>
<br /><a onclick ="javascript:ShowHide('lbl3')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl3>
  BUFFER_2K         = $800
  BUFFER_16         = $10
  
  CR                = $0D
  LF                = $0A
  DHCP_OPTIONS      = $F0
  DHCP_END          = $FF
  HARDWARE_ADDR_LEN = $06
  MAGIC_COOKIE_LEN  = $04
  UPD_HEADER_LEN    = $08
  MAX_DHCP_OPTIONS  = $10
  DHCP_PACKET_LEN        = $156 '342
  
  #0, CLOSED, TCP, UDP, IPRAW, MACRAW, PPPOE

  { DHCP Packet Pointers }
  DHCP_OP            = $00
  DHCP_HTYPE         = $01
  DHCP_HLEN          = $02
  DHCP_HOPS          = $03
  DHCP_XID           = $04
  DHCP_SEC           = $08
  DHCP_FLAGS         = $0A
  DHCP_CIADDR        = $0C  
  DHCP_YIADDR        = $10
  DHCP_SIADDR        = $14
  DHCP_GIADDR        = $18
  DHCP_CHADDR        = $1C
  DHCP_BOOTP         = $2C
  DHCP_MAGIC_COOKIE  = $EC
  DHCP_DHCP_OPTIONS  = $F0

  { DHCP Options Enum }
  SUBNET_MASK         = 01
  ROUTER_IP           = 03
  DOMAIN_NAME_SERVER  = 06
  HOST_NAME           = 12
  DOMAIN_NAME         = 15
  NTP_SERVER_IP       = 42
  WINS_NB_NAME_SERVER = 44
  WINS_NB_NODE_TYPE   = 46
  WINS_NB_SCOPE_ID    = 47
  REQUEST_IP          = 50
  IP_LEASE_TIME       = 51
  MESSAGE_TYPE        = 53
  DHCP_SERVER_IP      = 54
  PARAM_REQUEST       = 55

  { DHCP Message Types }
  DHCP_DISCOVER       = 1       
  DHCP_OFFER          = 2       
  DHCP_REQUEST        = 3       
  DHCP_DECLINE        = 4       
  DHCP_ACK            = 5       
  DHCP_NAK            = 6       
  DHCP_RELEASE        = 7

  { Packet Types }
  #0, SUCCESS, DISCOVER_ERROR, OFFER_ERROR, REQUEST_ERROR, ACK_ERROR, DUNNO_ERROR 

  HOST_PORT           = 68
  REMOTE_PORT         = 67

</pre>
<hr />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<h2 id = "lbl4">Global DATa </h2>
<br /><a onclick ="javascript:ShowHide('lbl5')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl5>
  noErr           <var>byte</var>  "Success", 0
  errDis          <var>byte</var>  "Discover Error", 0
  errOff          <var>byte</var>  "Offer Error", 0
  errReq          <var>byte</var>  "Request Error", 0
  errAck          <var>byte</var>  "Ack Error", 0
  errDunno        <var>byte</var>  "Unidentified Error", $0 
  requestIp       <var>byte</var>  00, 00, 00, 00
  errorCode       <var>byte</var>  $00
  magicCookie     <var>byte</var>  $63, $82, $53, $63
  paramReq        <var>byte</var>  SUBNET_MASK, ROUTER_IP, DOMAIN_NAME_SERVER, NTP_SERVER_IP ' Paramter Request; mask, router, domain name server, network time
  hostName        <var>byte</var>  "propnet", $0
  leaseTime       <var>byte</var>  $00, $00, $00, $00
  optionPtr       <var>long</var>  $F0
  buffPtr         <var>long</var>  $00_00_00_00
  transId         <var>long</var>  $00_00_00_00
  null            <var>long</var>  $00_00_00_00
  errors          <var>long</var>  @noErr, @errDis, @erroff, @errReq, @errAck, @errDunno
  hostptr         <var>long</var>  0       ' Holds pointer to hostname
  _ntpServer      <var>byte</var>  64, 147, 116, 229 '&lt;- This SNTP server is on the west coast. If your DHCP server provides a NTP-Server-IP it will get overridden.
  _dhcpServer     <var>byte</var>  $00, $00, $00, $00
  _router         <var>byte</var>  $00, $00, $00, $00    

</pre>
<hr /><br />
<h2 id = "lbl6">Used OBJects </h2>
<br /><a onclick ="javascript:ShowHide('lbl7')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl7>
  sock          : "Socket"
  wiz           : "W5100" 

</pre>
<hr /><br />
<h2 id = "lbl8">PUBlic Spin Methods</h2>
<hr /><h4 id = "lbl9">Init(buffer, socket)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl10')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl10><var>PUB</var> Init(buffer, socket)

  buffPtr := buffer
  hostPtr := @hostName
  'Set up the host socket 
  sock.Init(socket, UDP, HOST_PORT)

</pre>
<hr /><h4 id = "lbl11">SetHostname(hostnameaddress)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl12')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl12><var>PUB</var> SetHostname(hostnameaddress)
  hostptr := hostnameaddress

</pre>
<hr /><h4 id = "lbl13">GetErrorCode
</h4>
<br /><a onclick ="javascript:ShowHide('lbl14')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl14><var>PUB</var> GetErrorCode
  <var>return</var> errorCode

</pre>
<hr /><h4 id = "lbl15">GetErrorMessage
</h4>
<br /><a onclick ="javascript:ShowHide('lbl16')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl16><var>PUB</var> GetErrorMessage
  <var>if</var>(errorCode &gt; -1 <var>OR</var> errorCode &lt; DUNNO_ERROR)
    <var>return</var> @@errors[errorCode]
  <var>else</var>
    <var>return</var> @@errors[DUNNO_ERROR]

</pre>
<hr /><h4 id = "lbl17">GetLeaseTime
</h4>
<br /><a onclick ="javascript:ShowHide('lbl18')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl18><var>PUB</var> GetLeaseTime | lease
  lease := <var>byte</var>[@leaseTime][0] &lt;&lt; 24 | <var>byte</var>[@leaseTime][1]  &lt;&lt; 16 | <var>byte</var>[@leaseTime][2] &lt;&lt; 8 | <var>byte</var>[@leaseTime][3]
  <var>return</var> lease
  'return byte[@leaseTime][2]

</pre>
<hr /><h4 id = "lbl19">GetIp
</h4>
<br /><a onclick ="javascript:ShowHide('lbl20')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl20><var>PUB</var> GetIp
  <var>return</var> wiz.GetIp  

</pre>
<hr /><h4 id = "lbl21">SetRequestIp(octet3, octet2, octet1, octet0)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl22')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl22><var>PUB</var> SetRequestIp(octet3, octet2, octet1, octet0)
  requestIp[0] := octet3 
  requestIp[1] := octet2
  requestIp[2] := octet1
  requestIp[3] := octet0

</pre>
<hr /><h4 id = "lbl23">IsRequestIp
</h4>
<br /><a onclick ="javascript:ShowHide('lbl24')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl24><var>PRI</var> IsRequestIp
   <var>return</var> requestIp[0] | requestIp[1] | requestIp[2] | requestIp[3]

</pre>
<hr /><h4 id = "lbl25">GetRequestIP
</h4>
<br /><a onclick ="javascript:ShowHide('lbl26')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl26><var>PUB</var> GetRequestIP
  <var>return</var> @requestIp

</pre>
<hr /><h4 id = "lbl27">SetRouter(source)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl28')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl28><var>PUB</var> SetRouter(source)
  <var>bytemove</var>(@_router, source, 4)

</pre>
<hr /><h4 id = "lbl29">GetRouter
</h4>
<br /><a onclick ="javascript:ShowHide('lbl30')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl30><var>PUB</var> GetRouter
  <var>return</var> @_router

</pre>
<hr /><h4 id = "lbl31">SetDhcpServer(source)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl32')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl32><var>PUB</var> SetDhcpServer(source)
  <var>bytemove</var>(@_dhcpServer, source, 4)

</pre>
<hr /><h4 id = "lbl33">GetDhcpServer
</h4>
<br /><a onclick ="javascript:ShowHide('lbl34')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl34><var>PUB</var> GetDhcpServer
  <var>return</var>  @_dhcpServer

</pre>
<hr /><h4 id = "lbl35">SetNtpServer(source)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl36')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl36><var>PUB</var> SetNtpServer(source)
  <var>bytemove</var>(@_ntpServer, source, 4)

</pre>
<hr /><h4 id = "lbl37">GetNtpServer
</h4>
<br /><a onclick ="javascript:ShowHide('lbl38')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl38><var>PUB</var> GetNtpServer
  <var>return</var>  @_ntpServer

</pre>
<hr /><h4 id = "lbl39">DoDhcp(resetIp)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl40')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl40><var>PUB</var> DoDhcp(resetIp)
 
  errorCode := 0
  CreateTransactionId

  <var>if</var>(resetIp)
    wiz.SetIp(0,0,0,0)

  <var>ifnot</var>(DiscoverOffer)
    sock.Close
    <var>return</var> <var>false</var>

  <var>ifnot</var>(RequestAck) 
    sock.Close
    <var>return</var> <var>false</var>
 
  sock.Close 
  <var>return</var> <var>true</var>

</pre>
<hr /><h4 id = "lbl41">RenewDhcp
</h4>
<br /><a onclick ="javascript:ShowHide('lbl42')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl42><var>PUB</var> RenewDhcp
  errorCode := 0
  CreateTransactionId

  <var>ifnot</var>(RequestAck) 
    sock.Close
    <var>return</var> <var>false</var>
 
  sock.Close 
  <var>return</var> <var>true</var>

{ 

</pre>
<hr /><h4 id = "lbl43">SendReceive(buffer, len)
</h4>

<br />SendReceive:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Send request and waits for answer<br />

<br /><a onclick ="javascript:ShowHide('lbl44')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl44><var>PUB</var> SendReceive(buffer, len) | bytesToRead              'Send request and waits for answer
  <var>RESULT</var> := @null
  bytesToRead := 0
  sock.Open                                             'Open socket and Send Message
  sock.Send(buffer, len)
  bytesToRead := sock.Available
  <var>if</var>(bytesToRead =&lt; 0 )                                 'Check for a timeout
    bytesToRead~
  <var>else</var>  
    <var>RESULT</var> := sock.Receive(buffer, bytesToRead)         'Get the Rx buffer
  sock.Disconnect
}
{

</pre>
<hr /><h4 id = "lbl45">SendReceive(buffer, len)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl46')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl46><var>PUB</var> SendReceive(buffer, len) | bytesToRead, ptr 
  
  bytesToRead := 0

  'Open socket and Send Message 
  sock.Open
  sock.Send(buffer, len)

  bytesToRead := sock.Available
   
  'Check for a timeout
  <var>if</var>(bytesToRead =&lt; 0 )
    bytesToRead~
    <var>return</var> @null

  <var>if</var>(bytesToRead &gt; 0) 
    'Get the Rx buffer  
    ptr := sock.Receive(buffer, bytesToRead)

  sock.Disconnect
  <var>return</var> ptr
}

</pre>
<hr /><h4 id = "lbl47">UpdRxLen(buffer)
</h4>

<br />UpdRxLen:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;?debug?<br />

<br /><a onclick ="javascript:ShowHide('lbl48')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl48><var>PUB</var> UpdRxLen(buffer)                                    '?debug?
  <var>return</var> sock.DeserializeWord(buffer + 6)

</pre>
<hr /><br />
<h2 id = "lbl49">PRIvate Spin Methods </h2>
<hr /><h4 id = "lbl50">DiscoverOffer
</h4>
<br /><a onclick ="javascript:ShowHide('lbl51')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl51><var>PRI</var> DiscoverOffer | ptr

  InitRequest
  
  ptr := Discover
  <var>if</var>(ptr == -1)
    errorCode := DISCOVER_ERROR
    <var>return</var> <var>false</var>
        
  <var>ifnot</var>(Offer)
    errorCode := OFFER_ERROR
    <var>return</var> <var>false</var>

  <var>return</var> <var>true</var>

</pre>
<hr /><h4 id = "lbl52">RequestAck
</h4>
<br /><a onclick ="javascript:ShowHide('lbl53')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl53><var>PRI</var> RequestAck  | ptr

  InitRequest
  
  ptr := Request
  <var>if</var>(ptr == -1)
    errorCode := REQUEST_ERROR
    <var>return</var> <var>false</var>
    
  <var>ifnot</var>(Ack)
    errorCode := ACK_ERROR
    <var>return</var> <var>false</var>

  <var>return</var> <var>true</var> 

</pre>
<hr /><h4 id = "lbl54">InitRequest
</h4>
<br /><a onclick ="javascript:ShowHide('lbl55')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl55><var>PRI</var> InitRequest
  <var>bytefill</var>(buffPtr, 0, DHCP_MAGIC_COOKIE)
  sock.RemoteIp(255, 255, 255, 255)   
  sock.RemotePort(REMOTE_PORT)

</pre>
<hr /><h4 id = "lbl56">Discover
</h4>
<br /><a onclick ="javascript:ShowHide('lbl57')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl57><var>PRI</var> Discover | len
  'optionPtr is a global pointer used in the
  'WriteDhcpOption and ReadDhcpOption methods
  optionPtr := DHCP_OPTIONS + buffPtr
  
  FillOpHtypeHlenHops($01, $01, $06, $00)
  
  FillTransactionID
  FillMac
  FillMagicCookie
  WriteDhcpOption(MESSAGE_TYPE, 1, DHCP_DISCOVER)
  <var>if</var>(IsRequestIp)
    WriteDhcpOption(REQUEST_IP, 4, @requestIp)
  WriteDhcpOption(PARAM_REQUEST, 4, @paramReq)
  WriteDhcpOption(HOST_NAME, <var>strsize</var>(hostPtr), hostPtr)
  len := EndDhcpOptions
  <var>return</var> sock.SendReceive(buffPtr, len)

</pre>
<hr /><h4 id = "lbl58">Offer
</h4>
<br /><a onclick ="javascript:ShowHide('lbl59')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl59><var>PRI</var> Offer | ptr
  optionPtr := DHCP_OPTIONS + buffPtr

  'Move the pointer 8 bytes to the right
  'On receive the first 8 bytes in the UDP packet are IP:Port and len
  buffPtr += UPD_HEADER_LEN

  'Set the IP
  GetSetIp
  
  ' Set DNS server IP
  ptr := ReadDhcpOption(DOMAIN_NAME_SERVER)
  Wiz.copyDns(ptr+1, <var>byte</var>[ptr])

  'Set the Gateway IP
  'GetSetGateway

  'Set the ubnet mask
  ptr := ReadDhcpOption(SUBNET_MASK)
  wiz.CopySubnet(ptr+1, <var>byte</var>[ptr])

  'Set the router IP to the Gateway
  'Mike G 10/16/2012
  'From research and asking network guys the router IP (option 3)
  'should also be the gateway.
  ptr := ReadDhcpOption(ROUTER_IP)
  SetRouter(ptr+1)
  Wiz.CopyGateway(ptr+1, <var>byte</var>[ptr])

  'Set the DHCP server IP
  ptr := ReadDhcpOption(DHCP_SERVER_IP)
  SetDhcpServer(ptr+1) 

  'Set the NTP server IP
  ptr := ReadDhcpOption(NTP_SERVER_IP)
  <var>ifnot</var> ptr == -1
'    SetNtpServer(ptr+1) 

  ptr := ReadDhcpOption(MESSAGE_TYPE)                   '?
  
  'Reset the pointer
  buffPtr -= UPD_HEADER_LEN

  <var>return</var> <var>byte</var>[ptr][1] &amp; $FF == OFFER_ERROR

</pre>
<hr /><h4 id = "lbl60">Request
</h4>
<br /><a onclick ="javascript:ShowHide('lbl61')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl61><var>PRI</var> Request | len
  optionPtr := DHCP_OPTIONS + buffPtr
  
  <var>bytefill</var>(buffPtr, 0, BUFFER_2K)
  FillOpHtypeHlenHops($01, $01, $06, $00)
  FillTransactionID
  FillMac
  FillServerIp
  FillMagicCookie
  WriteDhcpOption(MESSAGE_TYPE, 1, DHCP_REQUEST)
  IsRequestIp
    WriteDhcpOption(REQUEST_IP, 4, @requestIp)
  WriteDhcpOption(DHCP_SERVER_IP, 4, GetDhcpServer)
  WriteDhcpOption(HOST_NAME, <var>strsize</var>(hostPtr), hostPtr)
  len := EndDhcpOptions
  <var>return</var> sock.SendReceive(buffPtr, len)

</pre>
<hr /><h4 id = "lbl62">Ack
</h4>
<br /><a onclick ="javascript:ShowHide('lbl63')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl63><var>PRI</var> Ack | ptr

  buffPtr += UPD_HEADER_LEN

  optionPtr := DHCP_OPTIONS + buffPtr

  ptr := ReadDhcpOption(IP_LEASE_TIME)
  FillLeaseTime(ptr+1)

  ptr := ReadDhcpOption(MESSAGE_TYPE) 
  
  buffPtr -= UPD_HEADER_LEN
  
  <var>return</var> <var>byte</var>[ptr][1] &amp; $FF == DHCP_ACK

</pre>
<hr /><h4 id = "lbl64">GetSetIp
</h4>
<br /><a onclick ="javascript:ShowHide('lbl65')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl65><var>PRI</var> GetSetIp | ptr
  ptr := buffPtr + DHCP_YIADDR
  Wiz.SetIp(<var>byte</var>[ptr][0], <var>byte</var>[ptr][1], <var>byte</var>[ptr][2], <var>byte</var>[ptr][3])
  requestIp[0] := <var>byte</var>[ptr][0]
  requestIp[1] := <var>byte</var>[ptr][1]
  requestIp[2] := <var>byte</var>[ptr][2]
  requestIp[3] := <var>byte</var>[ptr][3] 

</pre>
<hr /><h4 id = "lbl66">FillOpHTypeHlenHops(op, htype, hlen, hops)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl67')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl67><var>PRI</var> FillOpHTypeHlenHops(op, htype, hlen, hops)
  <var>byte</var>[buffPtr][DHCP_OP] := op
  <var>byte</var>[buffPtr][DHCP_HTYPE] := htype
  <var>byte</var>[buffPtr][DHCP_HLEN] := hlen
  <var>byte</var>[buffPtr][DHCP_HOPS] := hops  

</pre>
<hr /><h4 id = "lbl68">CreateTransactionId
</h4>
<br /><a onclick ="javascript:ShowHide('lbl69')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl69><var>PRI</var> CreateTransactionId
  transId := <var>CNT</var>
  ?transId

</pre>
<hr /><h4 id = "lbl70">FillLeaseTime(ptr)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl71')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl71><var>PRI</var> FillLeaseTime(ptr)
  'leaseTime :=  ptr[0] &lt;&lt; 24 |  ptr[1] &lt;&lt; 16 | ptr[2] &lt;&lt; 8 | ptr[3]
  <var>bytemove</var>(@leaseTime, ptr, 4)

</pre>
<hr /><h4 id = "lbl72">FillTransactionID
</h4>
<br /><a onclick ="javascript:ShowHide('lbl73')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl73><var>PRI</var> FillTransactionID
  <var>bytemove</var>(buffPtr+DHCP_XID, @transId, 4)

</pre>
<hr /><h4 id = "lbl74">FillMac
</h4>
<br /><a onclick ="javascript:ShowHide('lbl75')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl75><var>PRI</var> FillMac
  <var>bytemove</var>(buffPtr+DHCP_CHADDR, wiz.GetMac, HARDWARE_ADDR_LEN)    

</pre>
<hr /><h4 id = "lbl76">FillServerIp
</h4>
<br /><a onclick ="javascript:ShowHide('lbl77')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl77><var>PRI</var> FillServerIp
  <var>bytemove</var>(buffPtr+DHCP_SIADDR, GetDhcpServer, 4)

</pre>
<hr /><h4 id = "lbl78">FillMagicCookie
</h4>
<br /><a onclick ="javascript:ShowHide('lbl79')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl79><var>PRI</var> FillMagicCookie
  <var>bytemove</var>(buffPtr+DHCP_MAGIC_COOKIE, @magicCookie, MAGIC_COOKIE_LEN)

</pre>
<hr /><h4 id = "lbl80">WriteDhcpOption(option, len, data)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl81')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl81><var>PRI</var> WriteDhcpOption(option, len, data)
  <var>byte</var>[optionPtr++] := option
  <var>byte</var>[optionPtr++] := len
  
  <var>if</var>(len == 1)
    <var>byte</var>[optionPtr] := data
  <var>else</var>
    <var>bytemove</var>(optionPtr, data, len)
    
  optionPtr += len

</pre>
<hr /><h4 id = "lbl82">ReadDhcpOption(option)
</h4>
<br /><a onclick ="javascript:ShowHide('lbl83')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl83><var>PRI</var> ReadDhcpOption(option) | ptr                        '
  'Init pointer to options
  ptr := DHCP_OPTIONS + buffPtr

  'Repeat until we reach the end of the UPD packet
  <var>repeat</var> MAX_DHCP_OPTIONS

    <var>if</var>(<var>byte</var>[ptr] == DHCP_END)
      <var>return</var> -2
  
    <var>if</var>(<var>byte</var>[ptr++] == option)
      'return a pointer to the length byte
      <var>return</var> ptr

    'point to the next option code 
    ptr += <var>byte</var>[ptr] + 1

  <var>return</var> -1  

</pre>
<hr /><h4 id = "lbl84">EndDhcpOptions
</h4>
<br /><a onclick ="javascript:ShowHide('lbl85')" href="javascript:;">SOURCE CODE...</a>
<pre class=source id=lbl85><var>PRI</var> EndDhcpOptions | len                                '?
  <var>byte</var>[optionPtr] := DHCP_END
  <var>return</var> DHCP_PACKET_LEN

</pre>
<hr /><br />
<h2 id = "lbl86">Documentation </h2>

This .spin file supports PhiPi's great Spin Code Documenter found at
http://www.phipi.com/spin2html/

You can at any time create a .htm Documentation out of the .spin source.

If you change the .spin file you can (re)create the .htm file by uploading your .spin file
to http://www.phipi.com/spin2html/ and then saving the the created .htm page. 
<br />
<br />
<h2 id = "lbl87">MIT License </h2>
<pre>
 ______________________________________________________________________________________
|                            TERMS OF USE: MIT License                                 |                                                            
|______________________________________________________________________________________|
|Permission is hereby granted, free of charge, to any person obtaining a copy of this  |
|software and associated documentation files (the "Software"), to deal in the Software |
|without restriction, including without limitation the rights to use, copy, modify,    |
|merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    |
|permit persons to whom the Software is furnished to do so, subject to the following   |
|conditions:                                                                           |
|                                                                                      |
|The above copyright notice and this permission notice shall be included in all copies |
|or substantial portions of the Software.                                              |
|                                                                                      |
|THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   |
|INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         |
|PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    |
|HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF  |
|CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE  |
|OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                         |
|______________________________________________________________________________________|
</pre>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
		</div>
	</td></tr>
</table>
</div>
</body>
</html>	
